﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using System.Xml.Serialization;

namespace Powershell_ML
{
    public class Organization_Configuration : Exchange_Information
    {

        static PSObject Get_Mailbox = Collectorsvc.Program.Runner.Execute_Command_Once(Const.Get_OrganizationConfig);
        public Organization_Configuration() : this(Get_Mailbox)
        {


        }
        public Organization_Configuration(PSObject Object)
        {
            if (Object != null)
            {
                Powershell_ML.Famework.IEntry entry = new Powershell_ML.Famework.Powershell_Utility();
                this.Property = new List<PSPropertyInfo>();
                this.Property = entry.Property_Creator(Object);
                this.DN = entry.Extract_String_Property(this.Property, "DistinguishedName");
                this.Organization_Name = entry.Extract_String_Property(this.Property, "Name");
                this.MimeTypes_Supported = entry.Extract_String_Property(this.Property, "MimeTypes");
                this.Organization_Creation_Date = entry.Extract_String_Property(this.Property, "WhenCreatedUTC");
                this.Collected_Value = this.Property_Collection(Object);
                this.Organization_Summary = new List<string>();
                object Organization_Summarry = entry.Get_MultiValuedProperty(Object, "OrganizationSummary");
                this.Infrastructure_Report = new Dictionary<string, string>();
                this.Organization_Summary = entry.Icollection_To_List(Organization_Summarry);
                this.Organization_Summary.ForEach(delegate (string val)
                {
                    int strindex = val.LastIndexOf(",");
                    if(strindex > 0)
                    {
                        val = val.Substring(0, strindex);
                        int indexprop = val.IndexOf(",");
                        int indexvalue = val.LastIndexOf(",");
                        string propertyname = val.Substring(0, indexprop);
                        string propertyvalue = val.Substring(indexvalue +1);
                        this.Infrastructure_Report.Add(propertyname, propertyvalue);

                    }
                });
            }
        }

        [XmlIgnoreAttribute]
        public Dictionary<string,string> Infrastructure_Report
        {
            get;set;
        }
        public string Organization_Creation_Date
        {
            get; set;
        }
        public List<ICollection> Collected_Value
        {
            get;
            set;
        }
        public Dictionary<string, string> Wanted
        {
            get;
            set;
        }
        List<PSPropertyInfo> Property
        {
            get;
            set;
        }
        public string Organization_Name
        {
            get; set;
        }
        public string DN
        {
            get; set;
        }
        public string IsDirSyncRunning
        {
            get; set;
        }
        public string Legacy_Exchange_DN
        {
            get; set;
        }
        public string MimeTypes_Supported
        {
            get; set;
        }
        public List<string> Organization_Summary
        {
            get; set;
        }
    }
}
